<script>
    let stockComponent =  {
        template: `
<div class="tally-stock-component-box" style="width: 100%">
    <el-tabs type="border-card" class="stock-tabs" @tab-click="tabsClick" v-model="stockTabName">
      <el-tab-pane name="sales"> <span slot="label"><i class="el-icon-coin"></i> 销售/采购</span>
        <stock-sales ref="stockSalesRef"></stock-sales>
      </el-tab-pane>
      <el-tab-pane name="manage"><span slot="label"><i class="el-icon-pie-chart"></i> 库存管理</span>
        <stock-manage ref="stockManageRef"></stock-manage>
      </el-tab-pane>
      <el-tab-pane name="warehouse"><span slot="label"><i class="el-icon-menu"></i> 仓库管理</span>
         <stock-warehouse ref="stockHouseRef"></stock-warehouse>
      </el-tab-pane>
      <el-tab-pane name="product"><span slot="label"><i class="el-icon-set-up"></i> 产品管理</span>
         <stock-product ref="stockProductRef"></stock-product>
      </el-tab-pane>
    <el-tab-pane name="warehouse1"><span slot="label"><i class="el-icon-set-up"></i> 产品单位</span>
         <stock-warehouse1 ref="stockProductDanRef"></stock-warehouse1>
     </el-tab-pane>
    </el-tabs>
</div>
    `,
        computed: {
            currentTally () {
                return this.$store.state.currentTally
            },
            currentTallyId() {
                return this.$store.state.currentTallyId
            }
        },
        data:function(){
            return {
                stockTabName:'sales',
            }
        },
        mounted () {
            let that = this
            // 进销存相关 vuex
            that.$store.dispatch('getStockWareHouseList',that.currentTallyId).then((res)=>{
                if(res.length === 0) {
                    that.$confirm('检测到还没有添加仓库, 是否先去添加仓库？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        that.stockTabName = 'warehouse'
                        that.tabsClick('warehouse')
                    }).catch(() => {})
                }else {
                    that.$store.dispatch('getStockProductList',that.currentTallyId).then((res)=>{
                        if(res.length === 0) {
                            that.$confirm('检测到还没有添加产品, 是否先去添加产品？', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                that.stockTabName = 'product'
                                that.tabsClick('product')
                            }).catch(() => {})
                        }
                    })
                }
            })
            that.handleInitByTab(this.stockTabName)
        },
        methods:{
            tabsClick(t){

                this.handleInitByTab(t.name)
            },
            handleInitByTab(tabName) {

                switch (tabName) {
                    case 'product':
                        this.$refs['stockProductRef'].initData()
                        break;
                    case 'warehouse':
                        this.$refs['stockHouseRef'].initData()
                        break;
                    case 'manage':
                        this.$refs['stockManageRef'].initData()
                        break;
                    case 'sales':
                        console.log(this.$refs['stockSalesRef'])
                        this.$refs['stockSalesRef'].initData()
                        break;
                    case 'warehouse1':
                        this.$refs['stockProductDanRef'].initData()
                        break;
                    default:
                        break;
                }
            },
        }
    }
</script>
<style>
    .stock-tabs{
        border-left: 0px;
        border-right: 0px;
        border-bottom: 0px;
    }
</style>
